<?php
namespace haibao\cms\business\control\pc\index;

class WordLinkController extends IndexController{

    public function __construct($updateTime = null,$controlId,$isPublish){
        parent::__construct($updateTime,$controlId,$isPublish);
    }
    
    /**
     * 显示模版内容（模版动态数据的绑定和模版输出）
     * @param : String $content
     * @param : Array $controlData;
     */
    public function displayTemplateHtml(){
    
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $path = $this->generateHtmlPath(__CLASS__);
        
		$this->processWordLink($controlData);
        

        $this->generateHtml($path,$content);
        $content = $this->getHtml($path);
        // 解析内容 更换链接
        $content = $this->replaceCDNLink($content);
        return $content;
    }
    
    private function processWordLink($controlData){
    	$wordLinkList = array();
    	if($controlData['auto'] && isset($controlData['manual']['columnType'])){
    		$columnType = $controlData['manual']['columnType'];
    		foreach($controlData['auto'] as $data){
    			$value = json_decode($data['ParameterValue'],true);
    			if($columnType == $value['type']){
    				array_push($wordLinkList,$value);
    			}
    		}
    		
    		if(in_array($columnType,array('trend','beauty','star','say','library'))){
    			if($columnType == 'trend'){
    				$channel = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_FASHION);
    			}elseif($columnType == 'beauty'){
    				$channel = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BEAUTY);
    			}elseif($columnType == 'star'){
    				$channel = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STAR);
    			}elseif($columnType == 'say'){
    				$channel = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_SAY);
    			}elseif($columnType == 'library'){
    				$channel = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_PIC);
    			}
    			$temp = array('wordUrl'=>$channel,'wordTitle'=>'更多>>');
    			array_push($wordLinkList,$temp);
    		}
    	}
    	$this->assign('wordLinkList',$wordLinkList);
    }
} 